package base.多线程.线程池;

import cn.hutool.core.date.LocalDateTimeUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.*;

public class My_Th implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i % 2 == 1) System.out.println(Thread.currentThread().getName()+"::"+i);
        }
    }
}


class Text_1{
    public static void main(String[] args) {
        //ExecutorService pool = Executors.newCachedThreadPool();
        /*第一种内置线程池*/
//        ExecutorService pool = Executors.newFixedThreadPool(2);
//        pool.submit(new My_Th());
//        pool.submit(new My_Th());
//        pool.submit(new My_Th());
//        pool.submit(new My_Th());


        /*第二种自定义线程池*/
        //(核心线程数，最大线程数量，临时线程存活时间，时间单位，任务队列-阻塞队列，线程工厂，任务的拒接策略)
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,
                6,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        pool.submit(new My_Th());
        pool.submit(new My_Th());
        pool.submit(new My_Th());
        pool.submit(new My_Th());
        pool.submit(new My_Th());
        pool.submit(new My_Th());
        pool.submit(new My_Th());
        pool.submit(new My_Th());
        pool.submit(new My_Th());
        pool.submit(new My_Th());//10
    }
}